$(function () {
    $("#jqGrid").jqGrid({
        url: '../servicesettlementdetail/list',
        datatype: "json",
        colModel: [			
			{ label: 'id', name: 'id', index: 'id', key: true ,hidden:true},
			{ label: '劳务结算表汇总表ID', name: 'ssmid', index: 'ssmid'}, 			
			{ label: '员工编号', name: 'empid', index: 'empid'}, 			
			{ label: '员工状态', name: 'empstatus', index: 'empstatus'}, 			
			{ label: '部门', name: 'department', index: 'department'}, 			
			{ label: '姓名', name: 'name', index: 'name'}, 			
			{ label: '身份证号', name: 'cardno', index: 'cardno'}, 			
			{ label: '年', name: 'year', index: 'year'}, 			
			{ label: '月', name: 'month', index: 'month'}, 			
			{ label: '批次', name: 'batch', index: 'batch'}, 			
			{ label: '实收总额', name: 'totalPaid', index: 'total_paid'}, 			
			{ label: '单位应缴工伤部分(应收)', name: 'dwyjGongsYs', index: 'dwyj_gongs_ys'}, 			
			{ label: '单位应缴养老部分(应收)', name: 'dwyjYanglYs', index: 'dwyj_yangl_ys'}, 			
			{ label: '单位应缴失业部分(应收)', name: 'dwyjShiyYs', index: 'dwyj_shiy_ys'}, 			
			{ label: '单位应缴医疗部分(应收)', name: 'dwyjYilYs', index: 'dwyj_yil_ys'}, 			
			{ label: '单位应缴生育部分(应收)', name: 'dwyjShengyYs', index: 'dwyj_shengy_ys'}, 			
			{ label: '单位应缴大病部分(应收)', name: 'dwyjDabYs', index: 'dwyj_dab_ys'}, 			
			{ label: '单位应缴公积金部分(应收)', name: 'dwyjGongjjYs', index: 'dwyj_gongjj_ys'}, 			
			{ label: '单位应缴养老部分(应收)', name: 'gryjYanglYs', index: 'gryj_yangl_ys'}, 			
			{ label: '单位应缴失业部分(应收)', name: 'gryjShiyYs', index: 'gryj_shiy_ys'}, 			
			{ label: '单位应缴医疗部分(应收)', name: 'gryjYilYs', index: 'gryj_yil_ys'}, 			
			{ label: '单位应缴大病部分(应收)', name: 'gryjDabYs', index: 'gryj_dab_ys'}, 			
			{ label: '单位应缴公积金部分(应收)', name: 'gryjGongjjYs', index: 'gryj_gongjj_ys'}, 			
			{ label: '结算单位收管理费(实收)', name: 'jsdwGuanlifSs', index: 'jsdw_guanlif_ss'}, 			
			{ label: '结算单位收工资(实收)', name: 'jsdwSalarySs', index: 'jsdw_salary_ss'}, 			
			{ label: '结算单位收加班费(实收)', name: 'jsdwOvertimepaySs', index: 'jsdw_overtimepay_ss'}, 			
			{ label: '结算单位工伤(实收)', name: 'jsdwGongsSs', index: 'jsdw_gongs_ss'}, 			
			{ label: '结算单位养老(实收)', name: 'jsdwYanglSs', index: 'jsdw_yangl_ss'}, 			
			{ label: '结算单位失业(实收)', name: 'jsdwShiySs', index: 'jsdw_shiy_ss'}, 			
			{ label: '结算单位医疗(实收)', name: 'jsdwYilSs', index: 'jsdw_yil_ss'}, 			
			{ label: '结算单位生育(实收)', name: 'jsdwShengySs', index: 'jsdw_shengy_ss'}, 			
			{ label: '结算单位大病(实收)', name: 'jsdwDabSs', index: 'jsdw_dab_ss'}, 			
			{ label: '结算单位公积金(实收)', name: 'jsdwGongjjSs', index: 'jsdw_gongjj_ss'}, 			
			{ label: '结算单位意外(实收)', name: 'jsdwYiwaiSs', index: 'jsdw_yiwai_ss'}, 			
			{ label: '结算单位单位小计(实收)', name: 'jsdwUnitsubtotalSs', index: 'jsdw_unitsubtotal_ss'}, 			
			{ label: '结算个人养老(实收)', name: 'jsgrYanglSs', index: 'jsgr_yangl_ss'}, 			
			{ label: '结算个人失业(实收)', name: 'jsgrShiySs', index: 'jsgr_shiy_ss'}, 			
			{ label: '结算个人医疗(实收)', name: 'jsgrYilSs', index: 'jsgr_yil_ss'}, 			
			{ label: '结算个人生育(实收)', name: 'jsgrShengySs', index: 'jsgr_shengy_ss'}, 			
			{ label: '结算个人大病(实收)', name: 'jsgrDabSs', index: 'jsgr_dab_ss'}, 			
			{ label: '结算个人公积金(实收)', name: 'jsgrGongjjSs', index: 'jsgr_gongjj_ss'}, 			
			{ label: '结算个人个人小计(实收)', name: 'jsgrPersonsubtotalSs', index: 'jsgr_personsubtotal_ss'}, 			
			{ label: '单位补差工商', name: 'bcdwGongsYs', index: 'bcdw_gongs_ys'}, 			
			{ label: '单位补差养老', name: 'bcdwYanglYs', index: 'bcdw_yangl_ys'}, 			
			{ label: '单位补差失业', name: 'bcdwShiyYs', index: 'bcdw_shiy_ys'}, 			
			{ label: '单位补差医疗', name: 'bcdwYilYs', index: 'bcdw_yil_ys'}, 			
			{ label: '单位补差生育', name: 'bcdwShengyYs', index: 'bcdw_shengy_ys'}, 			
			{ label: '补差个人工伤', name: 'bcgrGongsYs', index: 'bcgr_gongs_ys'}, 			
			{ label: '补差个人养老', name: 'bcgrYanglYs', index: 'bcgr_yangl_ys'}, 			
			{ label: '补差个人失业', name: 'bcgrShiyYs', index: 'bcgr_shiy_ys'}, 			
			{ label: '补差个人生育', name: 'bcgrShengyYs', index: 'bcgr_shengy_ys'}, 			
			{ label: '补差个人医疗', name: 'bcgrYilYs', index: 'bcgr_yil_ys'}, 			
			{ label: '结算其他-各项保险社保补差(实收)', name: 'jsqtAllbxbcSs', index: 'jsqt_allbxbc_ss'}, 			
			{ label: '结算其他-个税(实收)', name: 'jsqtPersontaxSs', index: 'jsqt_persontax_ss'}, 			
			{ label: '结算其他-福利费(实收)', name: 'jsqtFulifSs', index: 'jsqt_fulif_ss'}, 			
			{ label: '结算其他-经济补偿(实收)', name: 'jsqtJingjibcSs', index: 'jsqt_jingjibc_ss'}, 			
			{ label: '结算其他-劳保用品(实收)', name: 'jsqtLaobaoSs', index: 'jsqt_laobao_ss'}, 			
			{ label: '结算其他-伙食(实收)', name: 'jsqtFoodSs', index: 'jsqt_food_ss'}, 			
			{ label: '结算其他-工伤费用(实收)', name: 'jsqtGongsSs', index: 'jsqt_gongs_ss'}, 			
			{ label: '结算其他-体检费用(实收)', name: 'jsqtTijianSs', index: 'jsqt_tijian_ss'}, 			
			{ label: '结算其他-税金(实收)', name: 'jsqtTaxSs', index: 'jsqt_tax_ss'}, 			
			{ label: '结算其他-社保补助(实收)', name: 'jsqtShebaobzSs', index: 'jsqt_shebaobz_ss'}, 			
			{ label: '结算其他-工会医疗互助(实收)', name: 'jsqtGonghyilSs', index: 'jsqt_gonghyil_ss'}, 			
			{ label: '结算其他-预留(实收)', name: 'jsqtRemarkoSs', index: 'jsqt_remarko_ss'}, 			
			{ label: '结算其他-预留(实收)', name: 'jsqtRemarktSs', index: 'jsqt_remarkt_ss'}, 			
			{ label: '结算其他-预留(实收)', name: 'jsqtRemarksSs', index: 'jsqt_remarks_ss'}, 			
			{ label: '结算其他-预留(实收)', name: 'jsqtRemarkfSs', index: 'jsqt_remarkf_ss'}, 			
			{ label: '结算其他-其他小计(实收)', name: 'jsqtSubtotalSs', index: 'jsqt_subtotal_ss'}, 			
			{ label: '结算其他-说明(实收)', name: 'jsqtExplainSs', index: 'jsqt_explain_ss'}, 			
			{ label: '基础信息-一审日期', name: 'basicFirstinstanceDate', index: 'basic_firstinstance_date'}, 			
			{ label: '基础信息-一审人', name: 'basicFirstinstancePerson', index: 'basic_firstinstance_person'}, 			
			{ label: '基础信息-二审日期', name: 'basicSecinstanceDate', index: 'basic_secinstance_date'}, 			
			{ label: '基础信息-二审人', name: 'basicSecinstancePerson', index: 'basic_secinstance_person'}, 			
			{ label: '结算其他-状态', name: 'basicStatus', index: 'basic_status'}, 			
			{ label: '结算其他-未清金额', name: 'basicOutstandingAmount', index: 'basic_outstanding_amount'}, 			
			{ label: '结算其他-税额', name: 'basicTaxAmount', index: 'basic_tax_amount'}			
        ],
		viewrecords: true,
        height: 385,
        rowNum: 10,
		rowList : [10,30,50],
        rownumbers: true, 
        rownumWidth: 25, 
        autowidth:true,
        multiselect: true,
        pager: "#jqGridPager",
        jsonReader : {
            root: "page.list",
            page: "page.currPage",
            total: "page.totalPage",
            records: "page.totalCount"
        },
        prmNames : {
            page:"page", 
            rows:"limit", 
            order: "order"
        },
        //字段太多自动加载横轴滚动条
        shrinkToFit:false,
        autoScroll: false,
        gridComplete:function(){
            //doResize();
            //显示grid底部滚动条
            //$("#jqGrid").closest(".ui-jqgrid-bdiv").css({ "overflow-x" : "scroll" });
            //隐藏grid底部滚动条
            //$("#jqGrid").closest(".ui-jqgrid-bdiv").css({ "overflow-x" : "hidden" });
        }
    });
});

var vm = new Vue({
	el:'#rrapp',
	data:{
		showList: true,
		title: null,
		serviceSettlementDetail: {}
	},
	methods: {
		query: function () {
			vm.reload();
		},
		add: function(){
			vm.showList = false;
			vm.title = "新增";
			vm.serviceSettlementDetail = {};
		},
		update: function (event) {
			var id = getSelectedRow();
			if(id == null){
				return ;
			}
			vm.showList = false;
            vm.title = "修改";
            
            vm.getInfo(id)
		},
		saveOrUpdate: function (event) {
			var url = vm.serviceSettlementDetail.id == null ? "../servicesettlementdetail/save" : "../servicesettlementdetail/update";
			$.ajax({
				type: "POST",
			    url: url,
			    contentType: "application/json",
			    data: JSON.stringify(vm.serviceSettlementDetail),
			    success: function(r){
			    	if(r.code === 0){
						alert('操作成功', function(index){
							vm.reload();
						});
					}else{
						alert(r.msg);
					}
				}
			});
		},
		del: function (event) {
			var ids = getSelectedRows();
			if(ids == null){
				return ;
			}
			
			confirm('确定要删除选中的记录？', function(){
				$.ajax({
					type: "POST",
				    url: "../servicesettlementdetail/delete",
				    contentType: "application/json",
				    data: JSON.stringify(ids),
				    success: function(r){
						if(r.code == 0){
							alert('操作成功', function(index){
								$("#jqGrid").trigger("reloadGrid");
							});
						}else{
							alert(r.msg);
						}
					}
				});
			});
		},
		getInfo: function(id){
			$.get("../servicesettlementdetail/info/"+id, function(r){
                vm.serviceSettlementDetail = r.serviceSettlementDetail;
            });
		},
		reload: function (event) {
			vm.showList = true;
			var page = $("#jqGrid").jqGrid('getGridParam','page');
			$("#jqGrid").jqGrid('setGridParam',{ 
                page:page
            }).trigger("reloadGrid");
		}
	}
});